package org.dk.poitalk.model;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.jappstart.model.auth.UserAccount;

@Entity
@MappedSuperclass
public abstract class DomainUserEntityImpl extends DomainEntityImpl implements DomainUserEntity {

    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private UserAccount userAccount;

	@Override
	public UserAccount getUserAccount() {
		return this.userAccount;
	}
	
	@Override
	public void setUserAccount(UserAccount userAccount) {
		this.userAccount = userAccount;
	}
	
	@Override
	public String toString() {
		return "DomainUserEntityImpl [" + super.toString() + ", userAccount=" + this.userAccount + "]";
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
			.appendSuper(super.hashCode())
			.append(this.userAccount)
			.hashCode();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof DomainUserEntityImpl)) {
			return false;
		}
		DomainUserEntityImpl castOther = (DomainUserEntityImpl) other;
		return new EqualsBuilder()
			.appendSuper(super.equals(castOther))
			.append(this.userAccount, castOther.userAccount)
			.isEquals();
	}
}
